<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Product;
use App\Banner;
class ProductController extends Controller
{
    protected $banner;

    public function __construct()
    {
        //获取banner
        $banner = Banner::where('entitle','=','product')->first();
        $this->banner  = $banner->banneritem[0];

    }
    public function index(){
        $banners=$this->banner;
        $product=Product::OrderBy('created_at','desc')->paginate(8);
        return view('home.product.index',compact('banners','product'));
    }
    public function show(Product $product){
        $banners=$this->banner;
        //浏览次自增
        Product::where('id',$product->id)->increment('views',1);
        return view('home.product.show',compact('banners','product'));
    }
}
